﻿namespace com.crownpack
{
    using System.Collections.Generic;
    using System.Linq;

    using com.crownpack.Extensions.SharePointExtensions;
    using com.crownpack.SharePoint;

    using Microsoft.SharePoint;

    using CustomContentType = Final_Definition_SiteLevel;

    public class InitiativesMasterList_Definition_WebLevel : InitiativesList_Definition_WebLevel
    {
        #region Constructors

        public InitiativesMasterList_Definition_WebLevel( SPFeatureReceiverProperties properties )
            : base(properties)
        {
        }

        ~InitiativesMasterList_Definition_WebLevel( )
        {
            Dispose( false );
        }

        #endregion Constructors

        #region Properties

        public ListDefn MasterInitiatives
        {
            get
            {
                return new ListDefn
                {
                    RootFolderName = "initiatives",
                    Title = "Initiatives",
                    Description = "Contains initiatives.",
                    ContentTypes = new string[ ]
                    {
                        CustomContentType.RollupInitiative.Name,
                        CustomContentType.UnknownInitiative.Name,
                    }.Distinct( ).ToList( )
                };
            }
        }

        #endregion Properties

        #region Methods

        public override void Create( )
        {
            CreateList( MasterInitiatives );
            CreateViews( );
        }

        public override void Delete( )
        {
            DeleteList( Initiatives, false );
        }

        void createView( string schemaName, string viewUrl, string viewTitle )
        {
            createView( schemaName, viewUrl, viewTitle, false );
        }

        void createView( string schemaName, string viewUrl, string viewTitle, bool defaultView )
        {
            using ( SPWeb spWeb = Properties.GetWeb( ) )
            {
                SPList spList = spWeb.Lists.GetListByRootFolder( Initiatives.RootFolderName );
                string schema = GetViewSchemaAsXmlString( schemaName );
                SPView spView = spList.CreateView( viewUrl, viewTitle, 300, true, defaultView, SPViewCollection.SPViewType.Html, schema, true );
            }
        }

        void CreateViews( )
        {
            createView( "Views.Master.ActiveInitiatives.xml", "ActiveInitiatives", "Active Initiatives" );
            createView( "Views.Master.AllInitiativesByCompany.xml", "All Initiatives by Company", "All Initiatives by Company" );
            createView( "Views.Master.ArchivedInitiatives.xml", "Archived Initiatives", "Archived Initiatives" );
            createView( "Views.Master.ByBranchByRep.xml", "By Branch by Rep", "By Branch by Rep" );
            createView( "Views.Master.ByBranchManager.xml", "By Branch Manager", "By Branch Manager" );
            createView( "Views.Master.ByInitiativeType.xml", "By Initiative Type", "By Initiative Type" );
            createView( "Views.Master.ByLocation.xml", "Location", "By Location" );
            createView( "Views.Master.ByProductCategory.xml", "ProductCategory", "By Product Category" );
            createView( "Views.Master.BySalesRep.xml", "SalesRep", "By Sales Rep" );
            createView( "Views.Master.ByStatus.xml", "Status", "By Status", true );
            createView( "Views.Master.HighLevel.xml", "HighL evel", "High Level" );
            createView( "Views.Master.ImplementedInitiatives.xml", "Implemented", "Implemented Initiatives" );
            createView( "Views.Master.ImpNotJDEConfirmed.xml", "Imp  NOT JDE Confirmed", "Imp. - NOT JDE Confirmed" );
            createView( "Views.Master.PastRealizationDate.xml", "PastRealizationDate", "Past Realization Date" );
            createView( "Views.Master.RejectedInitiatives.xml", "Rejected", "Rejected Initiatives" );
            createView( "Views.Master.RssView.xml", "rssview", "RssView" );
            createView( "Views.Master.StalledInitiatives.xml", "StalledInitiatives", "Stalled Initiatives" );
        }

        #endregion Methods
    }
}